<template>
  <el-row class="menu-page">
    <el-col>
      <el-menu
        mode="vertical"
        background-color="#181818"
        active-text-color="#fff"
        class="el-menu-vertical-demo"
        :default-active="defaultActive"
        @open="handleOpen"
        @close="handleClose"
      >
        <template v-for="item in menus">
          <!-- 多级 -->
          <el-submenu v-if="item.children" :index="item.path" :key="item.path">
            <template slot="title">
              <img
                v-if="item.icon !== ''"
                class="menu-icon"
                :src="item.icon"
                alt=""
              />
              <span slot="title">{{ item.name }}</span>
            </template>
            <router-link
              v-for="(citem, cindex) in item.children"
              :to="citem.path"
              :key="cindex"
            >
              <el-menu-item :index="citem.path">
                <span slot="title">{{ citem.name }}</span>
              </el-menu-item>
            </router-link>
          </el-submenu>
          <!-- 一级 -->
          <router-link v-else :to="item.path" :key="item.path">
            <el-menu-item :index="item.path">
              <img
                v-if="item.icon !== ''"
                class="menu-icon"
                :src="item.icon"
                alt=""
              />
              <span slot="title">{{ item.name }}</span>
            </el-menu-item>
          </router-link>
        </template>
      </el-menu>
    </el-col>
  </el-row>
</template>
<script>
import BoardGray from "@/assets/icon/menu/board-gray.png";
import BoardWhite from "@/assets/icon/menu/board-white.png";
import ContGray from "@/assets/icon/menu/cont-gray.png";
import ContWhite from "@/assets/icon/menu/cont-white.png";
import UserGray from "@/assets/icon/menu/user-gray.png";
import UserWhite from "@/assets/icon/menu/user-white.png";
import WorldGray from "@/assets/icon/menu/world-gray.png";
import WorldWhite from "@/assets/icon/menu/world-white.png";
export default {
  name: "leftmenu",
  data() {
    return {
      defaultActive: "/dashboard",
      // openeds: ["/world", "/contentSafe", "/user"], //  默认展开菜单 :default-openeds
      menus: [
        {
          icon: BoardGray,
          name: "主页",
          path: "/dashboard",
        },
        {
          icon: WorldGray,
          name: "外部世界",
          path: "/world",
          children: [
            { path: "/world/worldManage", name: "世界管理" },
            { path: "/world/worldFrag", name: "世界碎片" },
          ],
        },
        {
          icon: UserGray,
          name: "用户管理",
          path: "/user",
          children: [
            { path: "/user/userList", name: "用户列表" },
          ],
        },
 
        {
          icon: "",
          name: "vuex",
          path: "/testVuex",
        },
      ],
    };
  },
  created() {
    this.defaultActive = this.$route.path;
  },
  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
  },
};
</script>
<style lang="scss" scoped>
.menu-page {
  position: fixed;
  top: 100px;
  left: 0;
  min-height: 100%;
  background-color: #181818;
  z-index: 99;
  .el-menu {
    border: none;
  }
  .fa-margin {
    margin-right: 5px;
  }
  .el-menu-item {
    color: #999;
    font-size: 16px;
  }
  .el-menu--inline .el-menu-item {
    background-color: rgba($color: #666, $alpha: 0.3) !important;
    text-align: center;
    color: #666;
    font-size: 15px;
  }
  .el-menu--inline .el-menu-item:hover {
    background-color: #ccc !important;
    color: #999;
  }
  .el-menu-vertical-demo:not(.el-menu--collapse) {
    width: 240px;
    min-height: 400px;
  }
  .el-menu-vertical-demo {
    width: 35px;
  }
  .el-submenu .el-menu-item {
    min-width: 240px;
  }
  .menu-icon {
    display: inline-block;
    width: 20px;
    height: 20px;
    margin-right: 12px;
  }
  a {
    text-decoration: none;
  }
}
</style>
